package com.lhkj.ct.admin.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.lhkj.ct.base.annntation.Log;
import com.lhkj.ct.base.enums.ActionType;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.meta.admin.model.entity.TblDictData;
import com.lhkj.ct.meta.admin.service.SysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 字典数据表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2023-09-07
 */
@RestController
@RequestMapping("api/system/dict/data")
@ApiSupport(order = 9)
@Api(tags = {"09.字典数据"})
public class SysDictDataController {

    @Resource
    private SysDictDataService dictDataService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "字典数据列表")
//    //@RequiresPermissions("system:dict:list")
    @GetMapping("/list")
    public ActionResult<IPage<TblDictData>> list(TblDictData dictData, PageQuery pageQuery) {
        return ActionResult.success(dictDataService.selectDictDataList(dictData, pageQuery));
    }

    /**
     * 查询字典数据详细
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "字典数据详细")
//    //@RequiresPermissions("system:dict:query")
    @GetMapping(value = "/{id}")
    public ActionResult<TblDictData> getInfo(@PathVariable String id) {
        return ActionResult.success(dictDataService.getById(id));
    }


    /**
     * 新增字典类型
     */
    @ApiOperationSupport(order = 3)
//    //@RequiresPermissions("system:dict:add")
    @Log(title = "字典数据", actionType = ActionType.INSERT)
    @PostMapping
    public ActionResult<Void> add(@Validated @RequestBody TblDictData dict)
    {
        return ActionResult.judge(dictDataService.insert(dict));
    }

    /**
     * 修改保存字典类型
     */
    @ApiOperationSupport(order = 4)
//    //@RequiresPermissions("system:dict:edit")
    @Log(title = "字典数据", actionType = ActionType.UPDATE)
    @PutMapping
    public ActionResult<Void> edit(@Validated @RequestBody TblDictData dict) {
        return ActionResult.judge(dictDataService.updateById(dict));
    }

    /**
     * 删除字典类型
     */
    ////@RequiresPermissions("system:dict:remove")
    @Log(title = "字典类型", actionType = ActionType.DELETE)
    @DeleteMapping("delete")
    public ActionResult<Void> remove(@RequestBody List<String> ids) {
        dictDataService.removeByIds(ids);
        return ActionResult.success();
    }

}
